import java.util.*;
public class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minStack;
    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }
    
    public void push(int val) {
        if(stack.empty()){
            stack.push(val);
            minStack.push(val);
        }else{
            stack.push(val);
            if(val <= minStack.peek()){
                minStack.push(val);
            }
        }
    }
    
    public void pop() {
/*

        if(!stack.empty()) {
            int x = stack.pop();
            if(x == minStack.peek()) {
                minStack.pop();
            }
        }
*/
      /*  if(!stack.empty()) {
            int x = stack.peek();
          if(x == minStack.peek()){
             stack.pop();
             minStack.pop();
          }else{
             stack.pop();
          }
        }*/
         if(!stack.empty()) {
            if(stack.peek().equals(minStack.peek())){
                stack.pop();
                minStack.pop();
            }else{
                stack.pop();
            }
        }

    }
    
    public int top() {
        if(stack.empty()){
            return -1;
        }
        return stack.peek();
    }
    
    public int getMin() {
        if(minStack.empty()){
            return -1;
        }
        return minStack.peek();
    }
}